﻿


using System;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;


namespace DanGao.Infrastructure.Perssion
{
    /// <summary>
    /// 权限操作类。初始化所有权限以及行为
    /// </summary>
    public class PerssionOperating
    {
        public static IList<PerssionsAttribute> GetPerssionsWithControler()
        {
            List<PerssionsAttribute> list = new List<PerssionsAttribute>();
            var path = AppDomain.CurrentDomain.BaseDirectory + "bin\\" + "Demo.Web.dll";
            var ass = Assembly.LoadFrom(path);
            if( ass != null )
            {
                var types = ass.GetTypes().Where(t => t.Name.Contains("Controller")).ToList();
                foreach(var type in types)
                {
                    var methods = type.GetMethods();
                    foreach(var method in methods)
                    {
                        if (method.IsDefined(typeof(PerssionsAttribute), false))
                        {
                            var attr = method.GetCustomAttribute(typeof(PerssionsAttribute), false) as PerssionsAttribute;
                            if (attr != null && attr.type != PerssionType.Normal)
                                list.Add(attr);
                        }  
                    }
                }
            }
            return list;
        }

        public static void WriteData(List<PerssionsAttribute> list)
        { 
            
        }

    }
}
